import loginView from "$v/login"
import {
  loginRequest
} from '$a/loginApi'


export default async (req, res) => {
  res.render(loginView())

  // 给登录添加点击事件
  document.loginForm.loginBtn.onclick = async function (e) {
    // console.log(1111)
    e.preventDefault()

    const adminNameValue = document.loginForm.adminName.value;
    const passWordValue = document.loginForm.passWord.value;

    try {
      const loginRequestRequest =await loginRequest({
        adminName:adminNameValue,
        passWord:passWordValue
      })
      localStorage.setItem("user_token", loginRequestRequest.token)
      router.go("/adv/adminList")

    }catch (e){
      alert("登录异常" + e.message)
    }
  }

}